﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Perform
{
    public partial class frmResaleUpdate : Form
    {
        public frmResaleUpdate()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void frmResaleUpdate_Load(object sender, EventArgs e)
        {
            string sql = "select fid from flower";
            SqlDataReader sdr = Dal.DataHelper.ExecuteReader(sql);
            while (sdr.Read()) { cmbfid.Items.Add(sdr["fid"].ToString()); }
        }

        private void cmbfid_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sql = "select flower.fid,fname,fsalecost,rnumber,rdate from flower,resale where flower.fid =resale.fid and flower.fid='" + cmbfid.Text + "'";
            SqlDataReader sdr = Dal.DataHelper.ExecuteReader(sql);
            while (sdr.Read())
            {
                tbfname.Text = sdr["fname"].ToString();
                tbfsalecost.Text = sdr["fsalecost"].ToString();
                tbinumber.Text = sdr["rnumber"].ToString();
                dtptime.Text = sdr["rdate"].ToString();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string sql = string.Format("update resale set fid='{0}',rnumber='{1}',rdate='{2}' where fid='{3}'", cmbfid.Text.Trim(), tbinumber.Text.Trim(), dtptime.Text.Trim(), cmbfid.Text.Trim());
            if (Dal.DataHelper.sqlExecuteNonQuery(sql) > 0)
            {
                MessageBox.Show("修改零售信息成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                MessageBox.Show("修改零售信息失败！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            tbinumber.Text = "";
            tbfsalecost.Text = "";
            tbfname.Text = "";
            dtptime.Text = DateTime.Now.ToLongDateString();
            cmbfid.Text = "--请选择编号--";
        }
    }
}
